load("//bazel:skia_rules.bzl", "exports_files_legacy", "generate_cpp_files_for_headers", "select_multi", "skia_cc_deps", "skia_cc_library", "skia_filegroup", "split_srcs_and_hdrs")

package(
    default_applicable_licenses = ["//:license"],
)

licenses(["notice"])

exports_files_legacy()

# In separate groups for exporting to sksl.gni:skslc_deps.
SKSLC_FILES = [
    "GrMemoryPool.cpp",
    "GrMemoryPool.h",
]

split_srcs_and_hdrs(
    name = "core_skslc",
    files = SKSLC_FILES,
)

CORE_FILES = [
    "ClipStack.cpp",
    "ClipStack.h",
    "Device.cpp",
    "Device_drawTexture.cpp",
    "Device.h",
    "GrAppliedClip.h",
    "GrAttachment.cpp",
    "GrAttachment.h",
    "GrAuditTrail.cpp",
    "GrAuditTrail.h",
    "GrAutoLocaleSetter.h",
    "GrBackendSemaphore.cpp",
    "GrBackendSemaphorePriv.h",
    "GrBackendSurface.cpp",
    "GrBackendSurfacePriv.h",
    "GrBackendTextureImageGenerator.cpp",
    "GrBackendTextureImageGenerator.h",
    "GrBackendUtils.cpp",
    "GrBackendUtils.h",
    "GrBaseContextPriv.h",
    "GrBlurUtils.cpp",
    "GrBlurUtils.h",
    "GrBuffer.h",
    "GrBufferAllocPool.cpp",
    "GrBufferAllocPool.h",
    "GrBufferTransferRenderTask.cpp",
    "GrBufferTransferRenderTask.h",
    "GrBufferUpdateRenderTask.cpp",
    "GrBufferUpdateRenderTask.h",
    "GrCaps.cpp",
    "GrCaps.h",
    "GrCanvas.cpp",
    "GrCanvas.h",
    "GrClientMappedBufferManager.cpp",
    "GrClientMappedBufferManager.h",
    "GrClip.h",
    "GrColor.h",
    "GrColorInfo.cpp",
    "GrColorInfo.h",
    "GrColorSpaceXform.cpp",
    "GrColorSpaceXform.h",
    "GrContextThreadSafeProxy.cpp",
    "GrContextThreadSafeProxyPriv.h",
    "GrContext_Base.cpp",
    "GrCopyRenderTask.cpp",
    "GrCopyRenderTask.h",
    "GrCpuBuffer.h",
    "GrDDLContext.cpp",
    "GrDDLTask.cpp",
    "GrDDLTask.h",
    "GrDataUtils.cpp",
    "GrDataUtils.h",
    "GrDefaultGeoProcFactory.cpp",
    "GrDefaultGeoProcFactory.h",
    "GrDeferredProxyUploader.h",
    "GrDeferredUpload.h",
    "GrDeferredDisplayList.cpp",
    "GrDeferredDisplayListPriv.h",
    "GrDeferredDisplayListRecorder.cpp",
    "GrDirectContext.cpp",
    "GrDirectContextPriv.cpp",
    "GrDirectContextPriv.h",
    "GrDistanceFieldGenFromVector.cpp",
    "GrDistanceFieldGenFromVector.h",
    "GrDrawIndirectCommand.h",
    "GrDrawOpAtlas.cpp",
    "GrDrawOpAtlas.h",
    "GrDrawOpTest.cpp",
    "GrDrawOpTest.h",
    "GrDrawingManager.cpp",
    "GrDrawingManager.h",
    "GrDriverBugWorkarounds.cpp",
    "GrDstProxyView.h",
    "GrDynamicAtlas.cpp",
    "GrDynamicAtlas.h",
    "GrEagerVertexAllocator.cpp",
    "GrEagerVertexAllocator.h",
    "GrFPArgs.h",
    "GrFixedClip.cpp",
    "GrFixedClip.h",
    "GrFragmentProcessor.cpp",
    "GrFragmentProcessor.h",
    "GrFragmentProcessors.cpp",
    "GrFragmentProcessors.h",
    "GrGeometryProcessor.cpp",
    "GrGeometryProcessor.h",
    "GrGpu.cpp",
    "GrGpu.h",
    "GrGpuBuffer.cpp",
    "GrGpuBuffer.h",
    "GrGpuResource.cpp",
    "GrGpuResource.h",
    "GrGpuResourceCacheAccess.h",
    "GrGpuResourcePriv.h",
    "GrHashMapWithCache.h",
    "GrImageContext.cpp",
    "GrImageContextPriv.h",
    "GrImageInfo.cpp",
    "GrImageInfo.h",
    "GrManagedResource.cpp",
    "GrManagedResource.h",
    "GrMeshBuffers.cpp",
    "GrMeshBuffers.h",
    "GrMeshDrawTarget.cpp",
    "GrMeshDrawTarget.h",
    "GrNativeRect.h",
    "GrNonAtomicRef.h",
    "GrOnFlushResourceProvider.cpp",
    "GrOnFlushResourceProvider.h",
    "GrOpFlushState.cpp",
    "GrOpFlushState.h",
    "GrOpsRenderPass.cpp",
    "GrOpsRenderPass.h",
    "GrOpsTypes.h",
    "GrPaint.cpp",
    "GrPaint.h",
    "GrPersistentCacheUtils.cpp",
    "GrPersistentCacheUtils.h",
    "GrPipeline.cpp",
    "GrPipeline.h",
    "GrPixmap.h",
    "GrProcessor.cpp",
    "GrProcessor.h",
    "GrProcessorAnalysis.cpp",
    "GrProcessorAnalysis.h",
    "GrProcessorSet.cpp",
    "GrProcessorSet.h",
    "GrProcessorUnitTest.cpp",
    "GrProcessorUnitTest.h",
    "GrProgramDesc.cpp",
    "GrProgramDesc.h",
    "GrProgramInfo.cpp",
    "GrProgramInfo.h",
    "GrPromiseImageTexture.cpp",
    "GrProxyProvider.cpp",
    "GrProxyProvider.h",
    "GrRecordingContext.cpp",
    "GrRecordingContextPriv.cpp",
    "GrRecordingContextPriv.h",
    "GrRenderTarget.cpp",
    "GrRenderTarget.h",
    "GrRenderTargetProxy.cpp",
    "GrRenderTargetProxy.h",
    "GrRenderTask.cpp",
    "GrRenderTask.h",
    "GrRenderTaskCluster.cpp",
    "GrRenderTaskCluster.h",
    "GrResourceAllocator.cpp",
    "GrResourceAllocator.h",
    "GrResourceCache.cpp",
    "GrResourceCache.h",
    "GrResourceHandle.h",
    "GrResourceProvider.cpp",
    "GrResourceProvider.h",
    "GrResourceProviderPriv.h",
    "GrRingBuffer.cpp",
    "GrRingBuffer.h",
    "GrSPIRVUniformHandler.cpp",
    "GrSPIRVUniformHandler.h",
    "GrSPIRVVaryingHandler.cpp",
    "GrSPIRVVaryingHandler.h",
    "GrSWMaskHelper.cpp",
    "GrSWMaskHelper.h",
    "GrSamplerState.h",
    "GrScissorState.h",
    "GrSemaphore.h",
    "GrShaderCaps.cpp",
    "GrShaderCaps.h",
    "GrShaderVar.cpp",
    "GrShaderVar.h",
    "GrSimpleMesh.h",
    "GrStagingBufferManager.cpp",
    "GrStagingBufferManager.h",
    "GrStencilSettings.cpp",
    "GrStencilSettings.h",
    "GrStyle.cpp",
    "GrStyle.h",
    "GrSurface.cpp",
    "GrSurface.h",
    "GrSurfaceCharacterization.cpp",
    "GrSurfaceProxy.cpp",
    "GrSurfaceProxy.h",
    "GrSurfaceProxyPriv.h",
    "GrSurfaceProxyView.cpp",
    "GrSurfaceProxyView.h",
    "GrTestUtils.cpp",
    "GrTestUtils.h",
    "GrTTopoSort.h",
    "GrTexture.cpp",
    "GrTexture.h",
    "GrTextureProxy.cpp",
    "GrTextureProxy.h",
    "GrTextureProxyCacheAccess.h",
    "GrTextureProxyPriv.h",
    "GrTextureRenderTargetProxy.cpp",
    "GrTextureRenderTargetProxy.h",
    "GrTextureResolveManager.h",
    "GrTextureResolveRenderTask.cpp",
    "GrTextureResolveRenderTask.h",
    "GrThreadSafeCache.cpp",
    "GrThreadSafeCache.h",
    "GrThreadSafePipelineBuilder.cpp",
    "GrThreadSafePipelineBuilder.h",
    "GrTracing.h",
    "GrTransferFromRenderTask.cpp",
    "GrTransferFromRenderTask.h",
    "GrUniformDataManager.cpp",
    "GrUniformDataManager.h",
    "GrUserStencilSettings.h",
    "GrUtil.cpp",
    "GrUtil.h",
    "GrVertexChunkArray.cpp",
    "GrVertexChunkArray.h",
    "GrWaitRenderTask.cpp",
    "GrWaitRenderTask.h",
    "GrWindowRectangles.h",
    "GrWindowRectsState.h",
    "GrWritePixelsRenderTask.cpp",
    "GrWritePixelsRenderTask.h",
    "GrXferProcessor.cpp",
    "GrXferProcessor.h",
    "GrYUVABackendTextures.cpp",
    "GrYUVATextureProxies.cpp",
    "GrYUVATextureProxies.h",
    "PathRenderer.cpp",
    "PathRenderer.h",
    "PathRendererChain.cpp",
    "PathRendererChain.h",
    "SkGr.cpp",
    "SkGr.h",
    "StencilClip.h",
    "StencilMaskHelper.cpp",
    "StencilMaskHelper.h",
    "SurfaceContext.cpp",
    "SurfaceContext.h",
    "SurfaceDrawContext.cpp",
    "SurfaceDrawContext.h",
    "SurfaceFillContext.cpp",
    "SurfaceFillContext.h",
    "TestFormatColorTypeCombination.h",
]

split_srcs_and_hdrs(
    name = "core",
    files = CORE_FILES,
)

skia_filegroup(
    name = "android_srcs",
    srcs = [
        "GrAHardwareBufferImageGenerator.cpp",
        "GrAHardwareBufferImageGenerator.h",
        "GrAHardwareBufferUtils.cpp",
    ],
)

skia_filegroup(
    name = "srcs",
    srcs = [
        ":android_srcs",
        ":core_skslc_srcs",
        ":core_srcs",
        "//src/gpu/ganesh/effects:srcs",
        "//src/gpu/ganesh/geometry:srcs",
        "//src/gpu/ganesh/glsl:srcs",
        "//src/gpu/ganesh/gradients:srcs",
        "//src/gpu/ganesh/image:srcs",
        "//src/gpu/ganesh/mock:srcs",  # TODO(kjlubick, egdaniel) should this be test only?
        "//src/gpu/ganesh/ops:srcs",
        "//src/gpu/ganesh/surface:srcs",
        "//src/gpu/ganesh/tessellate:srcs",
        "//src/gpu/ganesh/text:srcs",
    ] + select_multi(
        {
            "//src/gpu:gl_ganesh": ["//src/gpu/ganesh/gl:srcs"],
            "//src/gpu:vulkan_ganesh": ["//src/gpu/ganesh/vk:srcs"],
            "@platforms//os:android": ["//src/gpu/ganesh/surface:android_srcs"],
            # TODO(kjlubick) d3d backend
        },
    ),
    visibility = ["//src/gpu:__pkg__"],
)

skia_filegroup(
    name = "objc_srcs",
    srcs = select_multi(
        {
            "//src/gpu:metal_ganesh": [
                "//src/gpu/ganesh/mtl:objc_srcs",
                "//src/gpu/ganesh/surface:mtl_objc_srcs",
            ],
        },
    ),
    visibility = ["//src/gpu:__pkg__"],
)

skia_filegroup(
    name = "private_hdrs",
    srcs = [
        ":core_hdrs",
        ":core_skslc_hdrs",
        "//src/gpu/ganesh/effects:private_hdrs",
        "//src/gpu/ganesh/geometry:private_hdrs",
        "//src/gpu/ganesh/glsl:private_hdrs",
        "//src/gpu/ganesh/gradients:private_hdrs",
        "//src/gpu/ganesh/image:private_hdrs",
        "//src/gpu/ganesh/mock:private_hdrs",  # TODO(kjlubick, egdaniel) should this be test only?
        "//src/gpu/ganesh/ops:private_hdrs",
        "//src/gpu/ganesh/surface:private_hdrs",
        "//src/gpu/ganesh/tessellate:private_hdrs",
        "//src/gpu/ganesh/text:private_hdrs",
    ] + select_multi(
        {
            "//src/gpu:gl_ganesh": ["//src/gpu/ganesh/gl:private_hdrs"],
            "//src/gpu:vulkan_ganesh": ["//src/gpu/ganesh/vk:private_hdrs"],
            "//src/gpu:metal_ganesh": ["//src/gpu/ganesh/mtl:private_hdrs"],
            # TODO(kjlubick) d3d backend
        },
    ),
    visibility = ["//src/gpu:__pkg__"],
)

skia_cc_deps(
    name = "deps",
    visibility = ["//src/gpu:__pkg__"],
    deps = select_multi(
        {
            "//src/gpu:gl_ganesh": ["//src/gpu/ganesh/gl:deps"],
            # TODO(kjlubick) mtl and d3d backend
        },
    ),
)

skia_cc_library(
    name = "ganesh",
    srcs = [
        ":core_skslc_srcs",
        ":core_srcs",
        "//src/gpu/ganesh/effects:srcs",
        "//src/gpu/ganesh/geometry:srcs",
        "//src/gpu/ganesh/glsl:srcs",
        "//src/gpu/ganesh/gradients:srcs",
        "//src/gpu/ganesh/image:srcs",
        "//src/gpu/ganesh/ops:srcs",
        "//src/gpu/ganesh/surface:srcs",
        "//src/gpu/ganesh/tessellate:srcs",
        "//src/gpu/ganesh/text:srcs",
        "//src/text/gpu:srcs",
        # TODO(kjlubick, egdaniel) Remove this coupling
        "//src/gpu/ganesh/mock:srcs",
    ],
    hdrs = [
        ":core_hdrs",
        ":core_skslc_hdrs",
        "//include/android:private_hdrs",
        "//include/gpu:ganesh_hdrs",
        "//include/gpu/ganesh:ganesh_hdrs",
        "//include/private/gpu/ganesh:private_hdrs",
        "//include/private/chromium:ganesh_private_hdrs",
        "//src/gpu/ganesh/effects:private_hdrs",
        "//src/gpu/ganesh/geometry:private_hdrs",
        "//src/gpu/ganesh/glsl:private_hdrs",
        "//src/gpu/ganesh/gradients:private_hdrs",
        "//src/gpu/ganesh/image:private_hdrs",
        "//src/gpu/ganesh/ops:private_hdrs",
        "//src/gpu/ganesh/surface:private_hdrs",
        "//src/gpu/ganesh/tessellate:private_hdrs",
        "//src/gpu/ganesh/text:private_hdrs",
        "//src/gpu/tessellate:private_hdrs",
        "//src/text/gpu:private_hdrs",
        # TODO(kjlubick, egdaniel) Remove this coupling
        "//src/gpu/ganesh/mock:private_hdrs",
        "//include/gpu/mock:public_hdrs",
    ],
    defines = ["SK_GANESH"],
    features = ["layering_check"],
    local_defines = ["SK_USE_LEGACY_GANESH_TEXT_APIS"],
    visibility = [
        "//src/gpu/ganesh:__subpackages__",
        "//tools/debugger:__pkg__",
    ],
    deps = [
        "//:core",
        "//modules/skcms",
        "//src/base",
        "//src/core:core_priv",
        "//src/gpu",
        "//src/sksl/codegen:gpu",
    ],
)

# TODO(lovisolo, kjlubick): Do this with a macro.
skia_cc_library(
    name = "ganesh_TEST_UTIL",
    testonly = True,
    srcs = [
        ":core_skslc_srcs",
        ":core_srcs",
        "//src/gpu/ganesh/effects:srcs",
        "//src/gpu/ganesh/geometry:srcs",
        "//src/gpu/ganesh/glsl:srcs",
        "//src/gpu/ganesh/gradients:srcs",
        "//src/gpu/ganesh/image:srcs",
        "//src/gpu/ganesh/ops:srcs",
        "//src/gpu/ganesh/surface:srcs",
        "//src/gpu/ganesh/tessellate:srcs",
        "//src/gpu/ganesh/text:srcs",
        "//src/text/gpu:srcs",
        "//src/utils:shader_utils_srcs",
        # TODO(kjlubick, egdaniel) Remove this coupling
        "//src/gpu/ganesh/mock:srcs",
    ],
    hdrs = [
        ":core_hdrs",
        ":core_skslc_hdrs",
        "//include/android:private_hdrs",
        "//include/gpu:ganesh_hdrs",
        "//include/gpu/ganesh:ganesh_hdrs",
        "//include/private/gpu/ganesh:private_hdrs",
        "//include/private/chromium:ganesh_private_hdrs",
        "//src/gpu/ganesh/effects:private_hdrs",
        "//src/gpu/ganesh/geometry:private_hdrs",
        "//src/gpu/ganesh/glsl:private_hdrs",
        "//src/gpu/ganesh/gradients:private_hdrs",
        "//src/gpu/ganesh/image:private_hdrs",
        "//src/gpu/ganesh/ops:private_hdrs",
        "//src/gpu/ganesh/surface:private_hdrs",
        "//src/gpu/ganesh/tessellate:private_hdrs",
        "//src/gpu/ganesh/text:private_hdrs",
        "//src/gpu/tessellate:private_hdrs",
        "//src/text/gpu:private_hdrs",
        "//src/utils:shader_utils_hdrs",
        # TODO(kjlubick, egdaniel) Remove this coupling
        "//src/gpu/ganesh/mock:private_hdrs",
        "//include/gpu/mock:public_hdrs",
    ],
    defines = [
        "GR_TEST_UTILS",
        "SK_GANESH",
    ],
    features = ["layering_check"],
    local_defines = ["SK_USE_LEGACY_GANESH_TEXT_APIS"],
    visibility = [
        "//src/gpu/ganesh:__subpackages__",
        "//tools:__subpackages__",
    ],
    deps = [
        "//:core",
        "//modules/skcms",
        "//src/base",
        "//src/core:core_priv",
        "//src/gpu",
        "//src/sksl/codegen:gpu",
    ],
)

generate_cpp_files_for_headers(
    name = "headers_to_compile",
    headers = [
        "GrBackendSemaphorePriv.h",
        "GrBackendSurfacePriv.h",
        "GrClip.h",
    ],
)
